<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>debounce</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const debounce = (handler, ms) => {
            let time = null;
            return function (...args) {
                clearTimeout(time);
                time = setTimeout(() => handler.apply(this, args), ms);
            };
        };
        window.addEventListener(
            'resize',
            debounce(() => {
                console.log(window.innerWidth);
                console.log(window.innerHeight);
            }, 250)
        );
    </script>
</body>

</html>